
export default {
    namespace: 'detail',
    state: {
        detail:''
    },
    reducers: {
        save(state, { payload }) {
            return Object.assign({}, state, payload);
        }
    },
    effects: {
        *init({ payload }, { put, call, select }) {
            const detail = yield put.resolve({
                type : '$request/post',
                payload : {
                    url : '/api/detail',
                    data : {
                        id : payload.id
                    }
                }
            });

            yield put({
                type : 'save',
                payload : {
                    detail
                }
            });
        },

        *delete({ payload }, { put, call, select }){
            const {id} = payload ; 
            yield put.resolve({
                type : '$request/post',
                payload : {
                    url : '/api/delete',
                    data : {
                        id 
                    }
                }
            });
            yield put.resolve({
                type : '$router/back'
            });
        }
    }
};